﻿using System.Collections.Generic;
using System.Linq;
using DB.SchemaSync.Library.Models;

namespace DB.SchemaSync.Library.Internal
{
	internal class IndexColumnComparer
	{
		public IndexColumnComparer(Table table, IEnumerable<IndexColumn> columns)
		{
			Table = table;
			Columns = columns;
		}

		public Table Table { get; }
		public IEnumerable<IndexColumn> Columns { get; }

		public override bool Equals(object obj)
		{
			var test = obj as IndexColumnComparer;
			if (test != null)
			{
				return Table.Equals(test.Table) && Columns.SequenceEqual(test.Columns);
			}

			return false;
		}

		public override int GetHashCode()
		{
			string columns = string.Join(",", Columns.Select(col => col.Name.ToLower()));
			return (Table.ToString() + columns).GetHashCode();
		}
	}
}